import Vue from 'vue';
import VueRouter from 'vue-router';

import configRouters from './modules'; // 默认指向目录下的 index 文件

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const router = new VueRouter({
    mode: 'hash',
    base: '/',
    routes: configRouters
});

// 路由守卫
// router.beforeEach((to, from, next) => {
//     if (to.path === '/login') return next();
//     const tokenStr = window.sessionStorage.getItem('userName');
//     if (!tokenStr) {
//         return next('/login');
//     }
//     // 调用 next 才能跳转页面
//     next();
// });

export default router;
